package com.zsinfo.guoss.supplier.activity;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.netcenter.Event.Response;
import com.example.netcenter.RetrofitBuilder;
import com.example.netcenter.Url.ConstantsCode;
import com.example.netcenter.bean.UserBean;
import com.zsinfo.guoss.supplier.R;
import com.zsinfo.guoss.supplier.base.BaseActivity;
import com.zsinfo.guoss.supplier.customize.CircleImageView;
import com.zsinfo.guoss.supplier.utils.SharedPreferencesUtil;

import butterknife.BindView;
import butterknife.OnClick;

public class UserInfoActivity extends BaseActivity {
    private Intent intent = null;

    @BindView(R.id.user_img)
    CircleImageView user_img;
    @BindView(R.id.tv_uesrName)
    TextView tv_uesrName;
    @BindView(R.id.mymobile)
    TextView mymobile;
    @BindView(R.id.station)
    TextView station;
    @BindView(R.id.dep)
    TextView dep;
    @BindView(R.id.manger)
    TextView manger;
    @BindView(R.id.alCount)
    TextView alCount;
    @BindView(R.id.tv_user_bank)
    TextView tv_user_bank;


    private UserBean MyUserBean = null;

    @OnClick({R.id.jump_bank, R.id.aliPay, R.id.UserName, R.id.Address_info, R.id.MainBusiness})
    void MyClick(View v) {

        if (intent == null)
            intent = new Intent();


        if (MyUserBean == null) {
            showToast("数据错误");
            return;
        }


        switch (v.getId()) {
            case R.id.jump_bank:
                intent.setClass(UserInfoActivity.this, AccountActivity.class);
                intent.putExtra("TypeValue", "银行卡账户");
                startActivity(intent);
                break;
            case R.id.aliPay:

                intent.setClass(UserInfoActivity.this, AddAccountActivity.class);
                intent.putExtra("TypeValue", "支付宝账号");
                intent.putExtra("TypeCount", MyUserBean.getData().getSupplier().getALiCount());
                startActivity(intent);
                break;


            case R.id.UserName:
                intent.setClass(UserInfoActivity.this, AddStationInfoActivity.class);
                intent.putExtra("TypeValue", "1");
                intent.putExtra("TypeCount", MyUserBean.getData().getSupplier().getName());
                startActivity(intent);
                break;

            //地址
            case R.id.Address_info:
                intent.setClass(UserInfoActivity.this, AddStationInfoActivity.class);
                intent.putExtra("TypeValue", "2");
                intent.putExtra("TypeCount", MyUserBean.getData().getSupplier().getAddress());
                startActivity(intent);
                break;
            //主营业务
            case R.id.MainBusiness:
                intent.setClass(UserInfoActivity.this, AddStationInfoActivity.class);
                intent.putExtra("TypeValue", "3");
                intent.putExtra("TypeCount", MyUserBean.getData().getSupplier().getBusiness());
                startActivity(intent);
                break;  //主营业务


        }

    }

    @Override
    protected int getContentLayoutRes() {
        return R.layout.activity_user_info;
    }

    @Override
    protected void initView() {
        setTitle("个人信息");
        setBackAndLeftTitle("").setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();

        GetNetCenter().GetNetCenter(this, RetrofitBuilder.CreateApi().SupplierInfo(ConstantsCode.supplier_info, SharedPreferencesUtil.getID()), new Response() {
            @Override
            public void OK(Object data) {

                UserBean userBean = (UserBean) data;

                MyUserBean = userBean;

                InfoAdapter(userBean);

            }

            @Override
            public void Fail(Throwable e) {

            }

            @Override
            public void complete() {

            }
        });
    }

    @Override
    protected void initNetData() {


    }


    void InfoAdapter(UserBean userBean) {


        Glide.with(this).load(userBean.getData().getSupplier().getFaceImg()).placeholder(R.drawable.user).into(user_img);

        tv_uesrName.setText(userBean.getData().getSupplier().getName());
        mymobile.setText(userBean.getData().getSupplier().getMobile());
        station.setText(userBean.getData().getSupplier().getWebsiteName());
        dep.setText(userBean.getData().getSupplier().getAddress());
        manger.setText(userBean.getData().getSupplier().getBusiness());

        alCount.setText(userBean.getData().getSupplier().getALiCount());

        String card = userBean.getData().getCard() + "张";
        tv_user_bank.setText(card);


    }


    @Override
    protected void customDestroy() {

    }
}
